package com.xinqing.test.atomic;

import com.alibaba.fastjson.JSON;
import com.xinqing.test.modle.Age;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @Author:CHQ
 * @Date:2020/11/18 10:17
 * @Description
 */
public class CompareAndSet {
    public static void main(String args[]){

        Map<String, List<Age>> map = new HashMap<>();

        List<Age> ageList = map.computeIfAbsent("1", k -> new ArrayList<>());
        ageList.add(new Age("1"));
        System.out.println(JSON.toJSONString(map)); // {"1":[{"age":"1"}]}

        List<Age> ageList1 = map.computeIfAbsent("1", k -> new ArrayList<>());
        ageList1.add(new Age("2"));
        System.out.println(JSON.toJSONString(map));  //{"1":[{"age":"1"},{"age":"2"}]}


    }
}
